﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace WebDownloader
{
    public partial class BBSListSetting : Form
    {
        public BBSListSetting()
        {
            InitializeComponent();
        }

        Action<string,int> m_OnBtnOkClicked;

        /// <summary>
        /// 初始化需要的数据
        /// </summary>
        /// <param name="param">参数</param>
        /// <param name="paramStep">参数每次增长的数目</param>
        public BBSListSetting InitData(string param, int paramStep = 0)
        {
            //TODO:HERE
            tb_param.Text = param;
            tb_paramStep.Text = paramStep.ToString();
            
            return this;
        }

        /// <summary>
        /// 在窗口点击“确定”时触发的事件
        /// </summary>
        public BBSListSetting AddConfrimListener(Action<string,int> onBtnOkClicked)
        {
            m_OnBtnOkClicked = onBtnOkClicked;
            return this;
        }

        /// <summary>
        /// OK被点击时，退出窗口并且回调
        /// </summary>
        void btn_OK_Click(object sender, EventArgs e)
        {
            string paramInput = tb_param.Text;
            string paramStepInput = tb_paramStep.Text;
            int paramStep;

            if (paramInput == "" )
            {
                MessageBox.Show("网址参数为空，这样很难猜测后续的帖子列表的网址");
                return;
            }
            else if ( false == int.TryParse(paramStepInput, out paramStep) )
            {
                MessageBox.Show("参数增长值不合法。这样怎么猜测后续的帖子列表的网址……");
                return;
            }


            if (m_OnBtnOkClicked != null)
            {
                m_OnBtnOkClicked(paramInput,paramStep);
            }

            this.Close();
            this.Dispose();
        }

    }
}
